﻿using System;
using System.Collections.Generic;
using System.Text;
using Newtonsoft.Json;
using System.IO;

namespace XProject.Commons.JsonUtil
{
    public class JavaScriptUtils
    {
        public static object DeserializeObject(string value, Type type, MissingMemberHandling missing)
        {
            StringReader sr = new StringReader(value);
            JsonSerializer jsonSerializer = new JsonSerializer();
            jsonSerializer.MissingMemberHandling = missing;
            object deserializedValue;

            using (JsonReader jsonReader = new JsonTextReader(sr))
            {
                deserializedValue = jsonSerializer.Deserialize(jsonReader, type);
            }

            return deserializedValue;
        }
    }
}
